
import React from 'react';
import { inject, observer } from 'mobx-react';
import { WeaTableNew } from 'comsMobx';
import RoomPlanDialog from '../public/roomPlan/index';

import { WeaErrorPage, WeaTools } from 'ecCom';
import MeetingDialog from '../public/dialog/index';
import {WeaLocaleProvider} from 'ecCom';
const getLabel = WeaLocaleProvider.getLabel;

@inject('meetingDialog')
@observer
class PreviewMeeting extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      dialogType: 'preview',
      RoomPlanContainer: false,
      meetingId: props.meetingId || '',
      visible: false,
    }
  }

  componentWillReceiveProps(nextProps) {
    if ('visible' in nextProps) {
      this.setState({visible: nextProps.visible});
    }
    if ('meetingId' in nextProps) {
      this.setState({meetingId: nextProps.meetingId});
    }
    if ('RoomPlanContainer' in nextProps) {
      this.setState({RoomPlanContainer: nextProps.RoomPlanContainer});
    }
  }

  componentWillUnmount() {
    //组件卸载时一般清理一些状态
  }

  render() {
    let { RoomPlanContainer, visible, dialogType, meetingId } = this.state;
    return (
      <div>
        <MeetingDialog
          setRoomPlan={this.setRoomPlan}
          setDialog={this.setDialog}
          setType={this.setType}
          setMeetingId={this.setMeetingId}
          setAll={this.setAll}
          type={dialogType}//新建为'create',查看为'preview',编辑edit,会议决议---待定
          visible={visible}//显隐受控
          doRefesh={this.doRefesh}//自定义刷新页面，不会关掉弹出框
          meetingId={meetingId} //会议id，查看会议时用到
          isInterval={true}//新建会议类型，true是周期会议， false是普通会议
          meetingDate={''}//新建日期
        />
        {RoomPlanContainer && <RoomPlanDialog
          setRoomPlan={this.setRoomPlan}
          setDialog={this.setDialog}
          setType={this.setType}
          setMeetingId={this.setMeetingId}
          canCreate={false}
          height={600}
          visible={RoomPlanContainer} />}
      </div>
    )
  }
  doRefesh = () => {

  }
  setAll = (meetingId, bool, type)=>{
    this.setState({
      meetingId:meetingId,
      visible:bool,
      dialogType:type
    })
  }
  setMeetingId = (meetingId) => {
    this.setState({ meetingId: meetingId })
  }
  setRoomPlan = (bool) => {
    this.setState({ RoomPlanContainer: bool })
  }
  setDialog = (bool) => {
    this.setState({ visible: bool })
  }
  setType = (type) => {
    this.setState({ dialogType: type })
  }
}

//组件检错机制
class MyErrorHandler extends React.Component {
  render() {
    const hasErrorMsg = this.props.error && this.props.error !== "";
    return (
      <WeaErrorPage msg={hasErrorMsg ? this.props.error : getLabel(383324,"对不起，该页面异常，请联系管理员")} />
    );
  }
}

PreviewMeeting = WeaTools.tryCatch(React, MyErrorHandler, { error: "" })(PreviewMeeting);

export default PreviewMeeting
